home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 43
/
Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso
/
Aminet
/
game
/
think
/
Connect4.lha
/
Connect4
/
source
/
computer_player.c
next >
Wrap
C/C++ Source or Header
|
2001-03-21
|
2KB
|
69 lines
#include "computer_player.h"
#include <stdlib.h>
#include <stdio.h>
#include <resources/battclock.h>
#include <clib/exec_protos.h>
#include <clib/battclock_protos.h>
/*
** Inputs:
** skill_level 1 being the lowest skill level
** 1 being the highest skill level
** filled 2D array describing gameboard contents
** columntop
**
** Result:
** Computer player's choice of column in which to place piece
** -1 on error
*/
APTR BattClockBase=NULL;
int computer_player (int skill_level, char **filled, char *columntop, BOOL newgame)
{
enum {ERROR=-1};
if (BattClockBase=OpenResource(BATTCLOCKNAME))
{
if (newgame)
srand(ReadBattClock()); // Seed the random generator with the system clock
// to ensure the moves are different each time
switch (skill_level)
{
// just needs columntop
case 1:
{
int result;
BOOL badmove=TRUE;
while (badmove)
{
result=rand();
result-=(result/7)*7;
if (columntop[result]!=4)
badmove=FALSE;
}
return result;
}
default:
return ERROR;
}
}
return ERROR;
}
/*
int main (void)
{
int i;
printf("%d ", computer_player(1, NULL, NULL, TRUE));
for (i=0; i<19; i++)
printf("%d ", computer_player(1, NULL, NULL, FALSE));
puts("");
return 0;
}
*/